import 'package:flutter/material.dart';
import 'mealModel.dart';
import 'meishiDetail.dart';

class CardVertical extends StatelessWidget {
  CardVertical(this.meal);

  final Meal meal;

  Widget build(BuildContext context) {
    return Card(
      child: Column(
        children: [
          meal.url == null?
          Image.asset('images/fail.png') :
          Image.network(
            meal.url!,
            errorBuilder: (context, error, stackTrace) {
              return Image.asset('images/fail.png');
            },
          ),
          Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                Text(meal.name),
                Text(
                    '￥${meal.price}',
                    style: TextStyle(
                        color: Colors.red
                    )
                )
              ]
          ),
          Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                Text(
                    '当日午餐',
                    style: TextStyle(
                      color: meal.mealType == '当日午餐'?
                      Colors.redAccent:Colors.black26,
                    )
                ),
                Text(
                    '次日午餐',
                    style: TextStyle(
                      color: meal.mealType == '次日午餐'?
                      Colors.redAccent:Colors.black26,
                    )
                ),
                Text(
                    '次日晚餐',
                    style: TextStyle(
                      color: meal.mealType == '次日晚餐'?
                      Colors.redAccent:Colors.black26,
                    )
                ),
              ]
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              meal.isCollect?
              Text('已收藏') :
              TextButton(
                  onPressed: (){},
                  child: Text('收藏至礼品库'))
            ],
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              TextButton(
                  onPressed: (){},
                  child: Text(
                      '用礼金兑换',
                      style: TextStyle(
                          color: Colors.amberAccent
                      )
                  )
              ),
              ElevatedButton(
                  style: ButtonStyle(
                      backgroundColor: MaterialStateProperty.all<Color>(Colors.orangeAccent)
                  ),
                  onPressed: (){},
                  child: Text(
                    '送给TA',
                    style: TextStyle(
                        color: Colors.pink
                    ),
                  )
              )
            ],
          ),
          Padding(padding: EdgeInsets.all(5.0))
        ],
      ),
    );
  }
}


class CardHorizontal extends StatelessWidget {
  CardHorizontal(this.meal, this.like);

  final Meal meal;
  final Function like;

  Widget build(BuildContext context) {
    return Card(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            Expanded(
              child: Column(
                children: [
                  meal.url == null?
                  Image.asset('images/fail.png') :
                  Image.network(
                    meal.url!,
                    errorBuilder: (context, error, stackTrace) {
                      return Image.asset('images/fail.png');
                    },
                  ),
                ],
              ),
            ),
            Expanded(
                child:Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Row(
                        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                        children: [
                          Text(meal.name),
                          Text(
                              '￥${meal.price}',
                              style: TextStyle(
                                  color: Colors.red
                              )
                          )
                        ]
                    ),
                    Row(
                        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                        children: [
                          Text(
                              '当日午餐',
                              style: TextStyle(
                                color: meal.mealType == '当日午餐'?
                                Colors.redAccent:Colors.black26,
                              )
                          ),
                          Text(
                              '次日午餐',
                              style: TextStyle(
                                color: meal.mealType == '次日午餐'?
                                Colors.redAccent:Colors.black26,
                              )
                          ),
                          Text(
                              '次日晚餐',
                              style: TextStyle(
                                color: meal.mealType == '次日晚餐'?
                                Colors.redAccent:Colors.black26,
                              )
                          ),
                        ]
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        meal.isCollect?
                        TextButton(
                            onPressed: (){
                              Navigator.push(
                                  context,
                                  MaterialPageRoute(
                                      builder: (context) => MealDetail(meal:meal, like:like)
                                  )
                              );
                            },
                            child: Text('已收藏')
                        )
                            :
                        TextButton(
                            onPressed: (){
                              Navigator.push(
                                  context,
                                  MaterialPageRoute(
                                      builder: (context) => MealDetail(meal:meal, like:like)
                                  )
                              );
                            },
                            child: Text('收藏至礼品库')
                        )
                      ],
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: [
                        TextButton(
                            onPressed: (){},
                            child: Text(
                                '用礼金兑换',
                                style: TextStyle(
                                    color: Colors.amberAccent
                                )
                            )
                        ),
                        ElevatedButton(
                            style: ButtonStyle(
                                backgroundColor: MaterialStateProperty.all<Color>(Colors.orangeAccent)
                            ),
                            onPressed: (){},
                            child: Text(
                              '送给TA',
                              style: TextStyle(
                                  color: Colors.pink
                              ),
                            )
                        )
                      ],
                    )
                  ],
                )
            )
          ],
        )
    );
  }
}